﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using CRMBiz;
using System.Configuration;
using CRMWeb.Utilities.Context;
using System.Data;

namespace CRMWeb.WebServices
{
    /// <summary>
    /// Summary description for SendEmailToUsers
    /// </summary>
    public class SendEmailToUsers : IHttpHandler
    {

        public void ProcessRequest(HttpContext context)
        {
            string sendingName = string.Empty;
            string smtpServer = string.Empty;
            DataTable dt = null;
            try
            {

                string fromName = context.Request.Params["fromName"];
                string password = context.Request.Params["password"];
                string toName = context.Request.Params["toName"];
                string attachmentFile = context.Request.Params["attachmentFile"];
                string attachmentsDrag = context.Request.Params["attachmentsDrag"];
                string subject = context.Request.Params["subject"];
                string bodyContent = context.Request.Params["bodyContent"];
                string response = string.Empty;
                dt = EmailSettingHandler.getSendingNameforEmail(fromName);
                if (dt.Rows.Count > 0)
                    response = ClientProfileHandler.SendEmail(fromName, dt.Rows[0]["SMTPserver"].ToString(), dt.Rows[0]["SendingName"].ToString(), password, toName, attachmentFile, attachmentsDrag, subject, bodyContent);
                else
                    response = "1";
                context.Response.Write(response);
            }
            catch (Exception ex)
            {
                ErrorHandler.saveErrorLog(ex, CMSContext.CurrentUser.MemberName);
            }
        }

        public bool IsReusable
        {
            get
            {
                return false;
            }
        }
    }
}